package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@JsonIgnoreProperties("handler")
public class NewsDetail extends BaseDomain {
    public static final Integer STATE_DRAFT = 0; //草稿
    public static final Integer STATE_RELEASE = 1; //发布
    public static final Integer STATE_RECOMMEND = 2; //推荐置顶


    private String title;       //日报标题
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;       //日报创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;       //日报发布时间

    private Long sequence;         //日报序号

    private NewsCatalog newsCatalog;       //日报目录编号

    private String coverUrl;        //日报背景

    private Integer state;          //日报状态

    private NewsContent newsContent;    //日报内容对象

    //状态
    public String getStateString() {
        String temp = "草稿";
        if (state == 1) {
            temp = "发布";
        } else if (state == 2) {
            temp = "推荐置顶";
        }
        return temp;
    }

    //封装成json
    public Object getJson() {
        Map map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("createTime", createTime);
        map.put("sequence", sequence);
        map.put("state", state);
        map.put("coverUrl", coverUrl);
        if (newsCatalog != null) {
            map.put("newsCatalogId", newsCatalog.getId());
            map.put("newsCatalogName", newsCatalog.getName());
        }
        return JSONUtil.toJSONString(map);
    }

}